//
//  MainTabBar.swift
//  LX_weibo
//
//  Created by LTT❤️ on 15/6/24.
//  Copyright © 2015年 LTT. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    
    
    private let buttonCount = 5
    override func layoutSubviews() {
        super.layoutSubviews()
        let W = bounds.width / CGFloat (buttonCount)
        let rect = CGRectMake(0, 0, W, bounds.height)
        
        var index = 0
        for V in subviews{
            if V is UIControl && !(V is UIButton){
                V.frame = CGRectOffset(rect, CGFloat(index)*W, 0)
                
                index += index == 1 ? 2 : 1
            }
        }
        compoesButton.frame = CGRectOffset(rect, 2*W, 0)
        
    }
    
    lazy var compoesButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_commpose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        return btn
        }()

}
